//
//  PublishDateVC.m
//  MovieDate
//
//  Created by 杨运涛 on 16/3/14.
//  Copyright © 2016年 MovieDate. All rights reserved.
//

#import "PublishDateVC.h"

@interface PublishDateVC ()

///票据图片上显示的内容
@property (weak, nonatomic) IBOutlet UILabel *pLblMovieName;
@property (weak, nonatomic) IBOutlet UILabel *pLblMovieTime;
@property (weak, nonatomic) IBOutlet UIImageView *pImgMovieType;

///下方显示的内容
@property (weak, nonatomic) IBOutlet UITextField *pTxtMovieName;
@property (weak, nonatomic) IBOutlet UITextField *pTxtPhone;

//时间
@property (weak, nonatomic) IBOutlet UIImageView *pImg1; //周末
@property (weak, nonatomic) IBOutlet UIImageView *pImg2; //都可以


//请客类型
@property (weak, nonatomic) IBOutlet UIImageView *pImgPay1; //我请客
@property (weak, nonatomic) IBOutlet UIImageView *pImgPay2; //AA制
@property (weak, nonatomic) IBOutlet UIImageView *pImgPay3; //你请客
@property (assign,nonatomic) NSString * payTypeIndex; //记录支付类型

@property (weak, nonatomic) IBOutlet UIButton *releaseOrEditMovieDateBTN;
@end

@implementation PublishDateVC

- (void)initInfo
{
    [super initInfo];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = NO;
    [self selAddLeftBackButton];
    [self selDefaultNavigationBackground];
    [self selDefaultNavigationWithTitle:@"发布影约"];
    if (self.movie_DateSate == em_release_movie_Date) {
         [self selDefaultNavigationWithTitle:@"发布影约"];
        [self.releaseOrEditMovieDateBTN setTitle:@"发布影约" forState:(UIControlStateNormal)];
        [self.releaseOrEditMovieDateBTN setTitle:@"发布影约" forState:(UIControlStateHighlighted)];
    }else{
        [self selDefaultNavigationWithTitle:@"编辑影约"];
        [self.releaseOrEditMovieDateBTN setTitle:@"编辑影约" forState:(UIControlStateNormal)];
        [self.releaseOrEditMovieDateBTN setTitle:@"编辑影约" forState:(UIControlStateHighlighted)];
        if ([[self.dictEditInfo objectForKey:@"time"] isEqualToString:@"0"]) {
            [self.pImg1 setImage:[UIImage imageNamed:@"publish_on"]];
            [self.pImg2 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pLblMovieTime setText:@"周末"];
        } else {
            [self.pImg1 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pImg2 setImage:[UIImage imageNamed:@"publish_on"]];
            [self.pLblMovieTime setText:@"都可以"];
        }
        
        if ([[self.dictEditInfo objectForKey:@"type"] isEqualToString:@"1"]) {
            [self.pImgPay1 setImage:[UIImage imageNamed:@"publish_on"]];
            [self.pImgPay2 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pImgPay3 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pImgMovieType setImage:[UIImage imageNamed:@"publish_me"]];
            self.payTypeIndex = @"1";
        } else if([[self.dictEditInfo objectForKey:@"type"] isEqualToString:@"3"]) {
            [self.pImgPay1 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pImgPay2 setImage:[UIImage imageNamed:@"publish_on"]];
            [self.pImgPay3 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pImgMovieType setImage:[UIImage imageNamed:@"publish_AA"]];
            self.payTypeIndex = @"3";
        } else {
            [self.pImgPay1 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pImgPay2 setImage:[UIImage imageNamed:@"publish_off"]];
            [self.pImgPay3 setImage:[UIImage imageNamed:@"publish_on"]];
            [self.pImgMovieType setImage:[UIImage imageNamed:@"publish_you"]];
            self.payTypeIndex = @"2";
        }
        
    }
    
    self.payTypeIndex = @"1";
    
    [self.pLblMovieName setText:self.movie.moiveTitle];
    [self.pTxtMovieName setText:self.movie.moiveTitle];
    [self.pTxtPhone setText:[User defaultUser].phone];
    
    [self.pTableView setTableFooterView:[UIView new]];
}

- (IBAction)btnSelectTimeAction:(UIButton *)sender
{
    int index = (int)sender.tag - 1300;
    if (index == 1) {
        [self.pImg1 setImage:[UIImage imageNamed:@"publish_on"]];
        [self.pImg2 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pLblMovieTime setText:@"周末"];
    } else {
        [self.pImg1 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pImg2 setImage:[UIImage imageNamed:@"publish_on"]];
        [self.pLblMovieTime setText:@"都可以"];
    }
}

- (IBAction)btnSelectPayTypeAction:(UIButton *)sender
{
    int index = (int)sender.tag - 1310;
    if (index == 1) {
        [self.pImgPay1 setImage:[UIImage imageNamed:@"publish_on"]];
        [self.pImgPay2 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pImgPay3 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pImgMovieType setImage:[UIImage imageNamed:@"publish_me"]];
        self.payTypeIndex = @"1";
    } else if(index == 2) {
        [self.pImgPay1 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pImgPay2 setImage:[UIImage imageNamed:@"publish_on"]];
        [self.pImgPay3 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pImgMovieType setImage:[UIImage imageNamed:@"publish_AA"]];
        self.payTypeIndex = @"3";
    } else {
        [self.pImgPay1 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pImgPay2 setImage:[UIImage imageNamed:@"publish_off"]];
        [self.pImgPay3 setImage:[UIImage imageNamed:@"publish_on"]];
        [self.pImgMovieType setImage:[UIImage imageNamed:@"publish_you"]];
        self.payTypeIndex = @"2";
    }
}

#pragma mark - UITableViewDataSource, UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"idfLikedCell"];
    return cell;
}

- (IBAction)releaseMovieDate:(id)sender {
    [SVProgressHUD show];
    User *user = [User defaultUser];
    if (self.movie_DateSate == em_release_movie_Date) {
        [TDNetwork requestReleaseMovieMeetPostURL:ReleaseMovieMeetIP
                                         andTitle:self.movie.moiveTitle
                                   andMeetAddress:@"重庆"
                                  andNeedVerified:0
                                    andTakePeople:2
                                         andPhone:user.phone
                                andReleaseAddress:user.pStrLocationAddress
                                            andJd:user.pStrLongitude
                                            andWd:user.pStrLatitude
                                       andPayType:self.payTypeIndex
                                       andMovieId:self.movie.movieId
                                      andMeetTime:self.pLblMovieTime.text
                                          andPlan:@""
                                         complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary)
         {
             if (succeed) {
                 switch ([ret intValue]) {
                     case 1:
                     {
                         [SVProgressHUD showSuccessWithStatus:@"发布成功"];
                         [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_ADD_MOVIE object:nil];
                         [self.navigationController popViewControllerAnimated:YES];
                     }
                         break;
                     case 2:
                         [SVProgressHUD showErrorWithStatus:@"已被限制发单"];
                         break;
                     case 3:
                         [SVProgressHUD showErrorWithStatus:@"此地区未开放"];
                         break;
                     default:
                         [SVProgressHUD showErrorWithStatus:@"未知错误"];
                         break;
                 }
             }else{
                 
                 [SVProgressHUD showErrorWithStatus:@"网络请求错误"];
             }
         }];
    }else{
        
        [TDNetwork updateReleaseMovieDateURl:Edit_MyReleaseMovieDate AppId:self.movie.appId title:self.movie.moiveTitle meetTime:self.pLblMovieTime.text meetAddress:@"重庆" needVerified:0 takePeople:@"2" phone:user.phone plan:@"" releaseAddress:user.pStrLocationAddress jd:user.pStrLongitude wd:user.pStrLatitude moivieId:self.movie.movieId payType:self.payTypeIndex complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
         if (succeed) {
             switch ([ret intValue]) {
                 case 1:
                 {
                     [SVProgressHUD showSuccessWithStatus:@"编辑成功"];
                     [self.navigationController popViewControllerAnimated:YES];
                 }
                     break;
                 case 2:
                     [SVProgressHUD showErrorWithStatus:@"已被限制发单"];
                     break;
                 case 3:
                     [SVProgressHUD showErrorWithStatus:@"此地区未开放"];
                     break;
                 case 4:
                     [SVProgressHUD showErrorWithStatus:@"权限问题 不是自己的影约"];
                     break;

                 default:
                     [SVProgressHUD showErrorWithStatus:@"未知错误"];
                     break;
             }
         }else{
             
             [SVProgressHUD showErrorWithStatus:@"网络请求错误"];
         }
     }];
        
   }
   }

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
